feat!: Refactor client constructor to use options pattern#4201
feat!: Refactor client constructor to use options pattern#4201stevehipwell wants to merge 6 commits into
Conversation
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4201 +/- ##
==========================================
+ Coverage 93.71% 97.77% +4.05%
==========================================
Files 209 189 -20
Lines 19772 19035 -737
==========================================
+ Hits 18529 18611 +82
+ Misses 1046 228 -818
+ Partials 197 196 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @stevehipwell.
Although I like the overall pattern, I have a few concerns with this PR.
First, the various fields within Client were originally exported individually, on a case-by-case basis, as users had need to access them. Suddenly unexporting all fields may wreak havoc.
Second, the clientMu was indeed needed to solve a race condition found when copying clients that were currently in-flight, if I'm remembering correctly.
Can we keep the nice builder pattern you've created here without unexporting all the fields and without removing the mutex that is protecting the client?
|
@gmlewis if you look at the code you'll see that Unexporting the values and putting them behind the options pattern to make the client immutable is core I the whole pattern. Could you provide some examples where these need changing and |
OK, I see. That sounds good to me. If you wouldn't mind please cleaning up all the non-idiomatic failures in the examples where I have marked them, that would be greatly appreciated, then we should be ready for a second LGTM+Approval. |
|
If you could also please investigate the 8 missed lines in code coverage in |
|
@gmlewis I've addressed you review comments and should have fixed the test coverage. I've also added exclusions for the examples and other code that shouldn't be be part of the coverage report which should make it easier to see what code should have been tested but hasn't been. |
|
@alexandear I'm still waiting on a reply on a couple of threads you opened? |
|
@gmlewis all review comments should now have been addressed. |
Thanks, @stevehipwell. |
This PR refactors the client to be immutable and to use the with options pattern for construction. This is a significant change but it should reduce the overall complexity and support better UX around new capabilities and backwards compatibility (e.g.
github.WithAPIVersion("2026-03-10")orgithub.WithGHESVersion("3.15")).Clientis immutableNewClientis the only way to create a newClientClientis created if you need to create a new one you can useCloneClientconfiguration is explicitNewClientcauses an early error instead of waiting for a failure or silently doing nothingclientMuwas unnecessaryCloses #3870
Closes #3915